/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package ar.com.remiseria.dao;

import ar.com.remiseria.entities.Documento;
import ar.com.remiseria.utils.HibernateUtils;
import org.hibernate.Criteria;
import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.Transaction;
import org.hibernate.criterion.Restrictions;

/**
 *
 * @author mcvalls
 */
public class DocumentoDAO extends GenericDAO{

    public Documento getDocumentoByNumeroAndTipo(Documento documento) throws HibernateException {
        
        Session session = HibernateUtils.getSessionFactory().getCurrentSession();
        Transaction tx = session.beginTransaction();
        
        Criteria criteria = session.createCriteria(Documento.class);
        criteria.add(Restrictions.eq("numero", documento.getNumero()));
        criteria.add(Restrictions.eq("tipoDeDocumento", documento.getTipoDeDocumento()));
        
        Documento doc = (Documento) criteria.uniqueResult();
        return doc;
    }
    
    public Documento getDocumentoByNumero(Documento documento){
        Session session = HibernateUtils.getSessionFactory().getCurrentSession();
        Transaction tx = session.beginTransaction();
        
        Criteria criteria = session.createCriteria(Documento.class);
        criteria.add(Restrictions.eq("numero", documento.getNumero()));
        
        documento = (Documento) criteria.uniqueResult();
        return documento;
    }
    
}
